<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const promise1 = new Promise((resolve, reject) => {
            // PromiseState - pending
            console.log('p1')
            resolve('success to p2')// PromiseState-fulfilled
        })
        // promise1.then() 默认返回的还是个 Promise
        const promise2 = promise1.then((res) => {
            console.log(res)
            return new Promise((resolve, reject) => {
                resolve('promise2 return')
                setTimeout(() => {
                    // 因为then方法是微任务，先微后宏,加个setTimeout保证p2 fulfilled
                    console.log(promise2, 'promise2 return')
                }, 0)

            })
        })
        console.log(1, promise1) // 1 Promise{fulfilled}
        console.log(2, promise2) // 2 Promise{pending}
    </script>
</body>

</html>